import request from '@/utils/request'
import axios from 'axios'
import Config from '@/settings'
import QueryString from 'qs'

export function login(username, password, code, uuid) {
  return request({
    url: 'auth/login',
    method: 'post',
    data: {
      username,
      password,
      code,
      uuid
    }
  })
}

export function getInfo() {
  return request({
    url: 'auth/info',
    method: 'get'
  })
}

export function getCodeImg() {
  return request({
    url: 'auth/code',
    method: 'get'
  })
}

export function logout() {
  return request({
    url: 'auth/logout',
    method: 'delete'
  })
}

// 登录SSO
export function loginSso(data) {
  return request({
    url: 'auth/loginSso?code=' + data,
    method: 'post'
  })
}

// 通过Token统一认证登录
export function loginUnified(params) {
  return request({
    url: '/auth/LoginByUnifyToken',
    params: params,
    method: 'post'
  })
}

// 春秋杏坛服务
const serviceCQXT = axios.create({
  baseURL: process.env.VUE_APP_BASE_API_CQXT,
  timeout: Config.timeout // 请求超时时间
})

// 登录春秋杏坛
export function loginCQXT(data) {
  return serviceCQXT({
    url: 'chat-api/api/login',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, // 设置表单提交格式
    method: 'post',
    data: QueryString.stringify(data)
  })
}

// 调用示例：
// password：md5加密

// loginCQXT({ username: "admin@fastagi", password: "0192023a7bbd73250516f069df18b500" })
//   .then(({ access_token, token_type }) => {
//     console.log(access_token, token_type);
//   })
